import * as echarts from 'echarts';
import { onUnmounted } from 'vue';

export function useEcharts( el = null ) {
  const echartInstance = echarts.init(el, null, { renderer: 'svg' });

  onUnmounted(() => { //  组件销毁，移除
    echartInstance.dispose();
  })

  function setOption(option) {
    echartInstance.setOption(option);
  }

  function resizeEchart() {
    echartInstance.resize();  //  页面尺寸变化的时候执行
  }

  //  返回处理函数
  return {
    echartInstance,
    setOption,
    resizeEchart
  }
}
